/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package itc.com.co.beans.utils;

import EntidadesCM.AfiliacionCM;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

public class AfiliadoDataModelT extends ListDataModel<AfiliacionCM> implements SelectableDataModel<AfiliacionCM> {

    private List<AfiliacionCM> cars = null;

    public AfiliadoDataModelT() {
    }

    public AfiliadoDataModelT(List<AfiliacionCM> data) {
        super(data);
        if (data != null && !data.isEmpty()) {
            cars = data;
        } else {
            cars = (List<AfiliacionCM>) getWrappedData();
        }

    }

    @Override
    public AfiliacionCM getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  

        try {
            if (cars == null || cars.isEmpty()) {
                cars = (List<AfiliacionCM>) getWrappedData();
            }

            for (AfiliacionCM car : cars) {
                if (car.getIdAfiliacion().equals(Integer.valueOf(rowKey))) {
                    return car;
                }
            }

        } catch (NumberFormatException e) {
        }
        return null;
    }

    @Override
    public Object getRowKey(AfiliacionCM car) {
        return car.getIdAfiliacion();
    }

    public void setCars(List<AfiliacionCM> cars) {
        this.cars = cars;
    }
}
